﻿@* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True *@
@using System.Collections
@using System.Collections.Generic
@using Hangfire
@using Hangfire.Dashboard
@using Hangfire.Dashboard.Pages
@using Hangfire.Dashboard.Resources
@inherits RazorPage
@{
    Layout = new LayoutPage(Queue);

    int from, perPage;

    int.TryParse(Query("from"), out from);
    int.TryParse(Query("count"), out perPage);

    var monitor = Storage.GetMonitoringApi();
    var pager = new Pager(from, perPage, monitor.EnqueuedCount(Queue));
    var enqueuedJobs = monitor.EnqueuedJobs(Queue, pager.FromRecord, pager.RecordsPerPage);
}

<div class="row">
    <div class="col-md-3">
        @Html.JobsSidebar()
    </div>
    <div class="col-md-9">
        @Html.Breadcrumbs(Queue, new Dictionary<string, string>
        {
            { "Queues", Url.LinkToQueues() }
        })

        <h1 class="page-header">@Queue <small>@Strings.EnqueuedJobsPage_Title</small></h1>

        @if (pager.TotalPageCount == 0)
        {
            <div class="alert alert-info">
                @Strings.EnqueuedJobsPage_NoJobs
            </div>
        }
        else
        {
            <div class="js-jobs-list">
                <div class="btn-toolbar btn-toolbar-top">
                    @if (!IsReadOnly)
                    {
                        <button class="js-jobs-list-command btn btn-sm btn-default"
                                data-url="@Url.To("/jobs/enqueued/delete")"
                                data-loading-text="@Strings.Common_Deleting"
                                data-confirm="@Strings.Common_DeleteConfirm"
                                disabled="disabled">
                            <span class="glyphicon glyphicon-remove"></span>
                            @Strings.Common_DeleteSelected
                        </button>
                    }
                    @Html.PerPageSelector(pager)
                </div>

                <div class="table-responsive">
                    <table class="table">
                        <thead>
                        <tr>
                            @if (!IsReadOnly)
                            {
                                <th class="min-width">
                                    <input type="checkbox" class="js-jobs-list-select-all"/>
                                </th>
                            }
                            <th class="min-width">@Strings.Common_Id</th>
                            <th class="min-width">@Strings.Common_State</th>
                            <th>@Strings.Common_Job</th>
                            <th class="align-right">@Strings.Common_Enqueued</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach (var job in enqueuedJobs)
                        {
                            <tr class="js-jobs-list-row hover @(job.Value == null || !job.Value.InEnqueuedState ? "obsolete-data" : null)">
                                @if (!IsReadOnly)
                                {
                                    <td>
                                        @if (job.Value != null)
                                        {
                                            <input type="checkbox" class="js-jobs-list-checkbox" name="jobs[]" value="@job.Key"/>
                                        }
                                    </td>
                                }
                                <td class="min-width">
                                    @Html.JobIdLink(job.Key)
                                    @if (job.Value != null && !job.Value.InEnqueuedState)
                                    {
                                        <span title="@Strings.Common_JobStateChanged_Text" class="glyphicon glyphicon-question-sign"></span>
                                    }
                                </td>
                                @if (job.Value == null)
                                {
                                    <td colspan="3"><em>@Strings.Common_JobExpired</em></td>
                                }
                                else
                                {
                                    <td class="min-width">
                                        @Html.StateLabel(job.Value.State)
                                    </td>
                                    <td class="word-break">
                                        @Html.JobNameLink(job.Key, job.Value.Job)
                                    </td>
                                    <td class="align-right">
                                        @if (job.Value.EnqueuedAt.HasValue)
                                        {
                                            @Html.RelativeTime(job.Value.EnqueuedAt.Value)
                                        }
                                        else
                                        {
                                            <em>@Strings.Common_NotAvailable</em>
                                        }
                                    </td>
                                }
                            </tr>
                        }
                        </tbody>
                    </table>
                </div>

                @Html.Paginator(pager)
            </div>
        }
    </div>
</div>